package com.xiaoxx.controller.code;

import com.xiaoxx.model.vo.code.FiledsVo;
import com.xiaoxx.model.vo.code.TablesVo;
import com.xiaoxx.service.CodeGenerationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Validated
@RestController
@RequestMapping("/api/codeGeneration")
@Api(value = "CodeGeneration", tags = "代码生成管理")
public class CodeGenerationColltroller {
    @Autowired
    private CodeGenerationService codeGenerationService;

    @ApiOperation("获取数据表")
    @RequestMapping(value = "/getTables", method = RequestMethod.GET)
    public List<TablesVo> getTables(@RequestParam(required = false) String name) {
        return codeGenerationService.getTables(name);
    }

    @ApiOperation("根据表名获取表结构")
    @RequestMapping(value = "/getTableFileds", method = RequestMethod.GET)
    public List<FiledsVo> getTableFileds(String name) {
        return codeGenerationService.getTableFileds(name);
    }
}
